<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="author" content="lijinbo" />
    <meta name="cdnload" content="jquery" />
    <title>mc-fetch 请求测试</title>
  </head>
  <style>
    button {
      margin: 16px;
      display: block;
    }
  </style>
  <body>
    <button id="mcGetData">get请求 - 数据</button>
    <button id="mcGetText">get请求 - 文本</button>
    <button id="mcPost">post请求</button>
    <button id="mcPostJson">post请求 - json</button>
    <button id="mcPostFormData">post请求 - ForData</button>

    <script type="module">
      import * as request from '/utils/module/RequestFetch.js'

      $('#mcGetData').on('click', async () => {
        const res = await request.get('/api/listData')
        console.log(res, '-->>> mcGetData')
      })
      $('#mcGetText').on('click', async () => {
        const res = await request.get('/assets/css/css3-flex.css')
        console.log(res, '-->>> mcGetText')
      })

      $('#mcPost').on('click', async () => {
        const data = {
          pageSize: 3
        }
        const res = await request.post('/api/userListData', data)
        console.log(res, '-->>> mcPost')
      })

      $('#mcPostJson').on('click', async () => {
        const data = {
          pageSize: 3
        }
        const res = await request.postJson('/api/userListData', data)
        console.log(res, '-->>> mcPostJson')
      })

      $('#mcPostFormData').on('click', async () => {
        const file = new File(['111', '222'], 'test.txt', { type: 'text/plain;charset=utf-8' })
        const data = new FormData()
        data.append('file', file)
        const res = await request.postFormData('/fileUpload', data)
        console.log(res, '-->>> mcPostFormData')
      })
    </script>
  </body>
</html>
